<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ page import="Database.Document" %>
<%@ page import="Database.DocumentVector" %>
<%@ page import="InformationRetriever.Formulas" %>

<%@ include file="/header" %>

<%     
    DocumentVector list = null;
    int i = 0;
    
    try
    {
        list = (DocumentVector)request.getAttribute("list");
    }
    catch(Exception e)
    {
        ///if the file list is null, redirect to the proper  page...
        response.sendRedirect(siteRoot+"/Query");
    }
    
    if( list == null
        || request.getParameter("query") == null
        || request.getParameter("formula") == null
        || request.getParameter("n") == null)
    {
        response.sendRedirect(siteRoot+"/Query");
    }
%>

    <div id="queryForm">
        <p>Enter some keywords to perform a simple query.</p>
        <form action="<%=siteRoot%>/Query" method="get">
            <input type="text" name="query" value="<%=request.getParameter("query")%>" alt="Enter your query" title="Enter your query" />
            <select name="n" alt="Show the first n documents" title="Show the first n documents">
                <option value="1" <% if(request.getParameter("n").equals("1")) out.write("selected");%> /> 1
                <option value="2" <% if(request.getParameter("n").equals("2")) out.write("selected");%> /> 2
                <option value="3" <% if(request.getParameter("n").equals("3")) out.write("selected");%> /> 3
                <option value="4" <% if(request.getParameter("n").equals("4")) out.write("selected");%> /> 4
                <option value="5" <% if(request.getParameter("n").equals("5")) out.write("selected");%> /> 5
                <option value="6" <% if(request.getParameter("n").equals("6")) out.write("selected");%> /> 6
                <option value="7" <% if(request.getParameter("n").equals("7")) out.write("selected");%> /> 7
                <option value="8" <% if(request.getParameter("n").equals("8")) out.write("selected");%> /> 8
                <option value="9" <% if(request.getParameter("n").equals("9")) out.write("selected");%> /> 9
                <option value="10" <% if(request.getParameter("n").equals("10")) out.write("selected");%> /> 10
            </select>
            <select name="formula" alt="Select a formula" title="Select a formula">
                <option value="<%=Formulas.InnerProduct%>"      <% if(request.getParameter("formula").equals(Formulas.InnerProduct.toString())) out.write("selected"); %> />      <%=Formulas.InnerProduct.title()%>
                <option value="<%=Formulas.Cosine%>"            <% if(request.getParameter("formula").equals(Formulas.Cosine.toString())) out.write("selected"); %> />            <%=Formulas.Cosine.title()%>
                <option value="<%=Formulas.DiceCoefficient%>"   <% if(request.getParameter("formula").equals(Formulas.DiceCoefficient.toString())) out.write("selected"); %> />   <%=Formulas.DiceCoefficient.title()%>
                <option value="<%=Formulas.JaccardCoefficient%>"<% if(request.getParameter("formula").equals(Formulas.JaccardCoefficient.toString())) out.write("selected"); %> /><%=Formulas.JaccardCoefficient.title()%>
                <option value="<%=Formulas.EuclideanDistance%>" <% if(request.getParameter("formula").equals(Formulas.EuclideanDistance.toString())) out.write("selected"); %> /> <%=Formulas.EuclideanDistance.title()%>
                <option value="<%=Formulas.ManhattanDistance%>" <% if(request.getParameter("formula").equals(Formulas.ManhattanDistance.toString())) out.write("selected"); %> /> <%=Formulas.ManhattanDistance.title()%>
            </select>
            <input type="image" id="querySubmitIcon" src="<%=siteRoot%>/query/query.png" alt="Find relevant documents" title="Find relevant documents" />
        </form>
        <p>Or <a href="<%=siteRoot%>/Compare">compare two indexed documents</a>.</p>
    </div>
    
    <h2>Results</h2>
    
    <div id="resultQuery">
        <%           
            for(Document doc : list)
            {
        %>
        <h3><%=++i%>. <a href="<%=doc.getUrl()%>" alt=""><%=doc%></a></h3>
        <%
            }
        %>
    </div>
    
<%@ include file="/footer" %>
